<template>
    <div class="container">
        <!-- 顶部导航栏 -->
        <el-header>
            <div class="topbar">
                <span class="shop-list" style="margin-left: 600px">我的门店</span>
            </div>
        </el-header>

        <!-- 主体内容 -->
        <el-main>
            <el-row>
                <!-- 使用 v-for 循环遍历商家数据，并使用 el-card 显示 -->
                <el-col :span="4" v-for="shop in shops" :key="shop.shopId">
                    <el-card class="shop-card" @click="toShopInfo(shop.shopId)">
                        <img :src="shop.shopImg" class="shop-img" :alt="shop.shopName">
                        <div slot="header" class="shop-name">{{ shop.shopName }}</div>
                    </el-card>
                </el-col>
            </el-row>
            <el-button type="primary" style="margin-left: 690px" @click="addShop">添加门店</el-button>
        </el-main>


    </div>

</template>

<script setup>
import {onMounted, ref} from 'vue';
import {getShopByBusinessId} from "@/api/shop";
import {useRouter} from "vue-router";
import {getBusinessInfo} from "@/api/business";
import router from "@/router";
const shops=ref([])
const business=ref({})
onMounted(async () => {
    let result = await getBusinessInfo()
    business.value=result.data
    let result2=await getShopByBusinessId(business.value.shopId)
    shops.value=result2.data

})

function toShopInfo(shopId){
    router.push({path:'/shopInfo',query:{shopId:shopId}})
}
function addShop(){
    window.open(`/addShop`, '_blank');
}
</script>

<style>
.container {
    width: 100%;
    height: 100vh;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
}

.shop-list {
    font-size: 24px;


}

.username {
    font-size: 18px;
}

.shop-card {
    margin: 10px;
}

.shop-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.shop-name {
    text-align: center;
}
</style>